Table of Contents
Content Tree

Overview

EO.Pdf provides a set of content classes. To create a PDF file, you create a content tree, then render the content tree through an AcmRender class to create the final PDF file.

Content Tree

To build a content tree, simply add one content object to another content object's Children collection. When a content object is placed in another content object's Children collection, it is rendered inside that content object. For example, the following code renders some text inside a gray block:

//Create a block object
AcmBlock block = new AcmBlock();

//Set the background of the block to gray
block.Style.BackgroundColor = Color.Gray;        

//Create a text object
AcmText text = new AcmText("Hello World!");

//Add the text into the block
block.Children.Add(text);

Creating Content Tree with a Single Statement

The above sample code can also be written as:

//Create a block object
AcmBlock block = new AcmBlock(new AcmText("Hello World!"));

Note that the AcmText object is passed directly to the AcmBlock object through the AcmBlock object's constructor. When an object is passed in through the constructor, it is automatically added as a child object. You can pass as many child objects as needed. For example:

//Create a block object with some text
AcmBlock block = new AcmBlock(
    new AcmText("some "),
    new AcmBold(new AcmText("bold")),
    new AcmText(" text"));

Each content object provides a set of properties that can be used to customize the object's appearance and behavior. For example, an AcmText's font size can be set with the following code:

//Create the text object
AcmText text = new AcmText("some text");

//Set the text object's font
text.Style.FontSize = 20f;

You can also set a property by calling SetProperty function. For example, the above code can be written as:

//Create the text object
AcmText text = new AcmText("some text");

//Set the text object's font
text.SetProperty("Style.FontSize", 20f);

SetProperty returns the AcmContent object itself. This makes it possible to write the following code:

//Create a block object with several child objects
AcmBlock block = new AcmBlock(
    new AcmText("some "),
    new AcmText("big red")
      .SetProperty("Style.FontSize", 20f)
      .SetProperty("Style.ForegroundColor", Color.Red),
    new AcmText(" text"));

This allows you to construct complex content tree through a single statement without having to create a lot of local variables for different contents.

Content Classes

In addition to AcmText, EO.Pdf provides the following content class types:

Content Type Remarks
AcmBlock Serves as the base class of all block contents. Can also be used directly.
AcmBold Automatically applies bold font style for enclosed contents.
AcmImage Used to place an image in a PDF file.
AcmItalic Automatically applies italic font style for enclosed contents.
AcmLink Used to create a navigation link in a PDF file.
AcmPageBreak Create a page break.
AcmLineBreak Create a line break.
AcmParagraph Used to create a new paragraph in a PDF file.
AcmTable Used to create a two dimensional table in a PDF file.
AcmField, AcmTextBox, AcmListBox, AcmCheckBox Uses these types to create PDF fill-in form.

Most content types are self-explanatory. Some content types are much more powerful and have many customization options. Please see documentation for the corresponding type for more details.